package com.jiangkai.common.shiro.filter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.shiro.web.filter.AccessControlFilter;

import com.jiangkai.utils.LoggerUtils;



/**
 * session 保存登录账户信息
 * 如果使用记住我时，session里是没有改用户信息的 需要 拦截添加到session中
 * @author jiangkia
 *
 */
public class UserSessionFilter extends AccessControlFilter {

	@Override
	protected boolean isAccessAllowed(ServletRequest request,
			ServletResponse response, Object mappedValue) throws Exception {
		LoggerUtils.debug(UserSessionFilter.class, "isAccessAllowed");
//		Subject subject  = SecurityUtils.getSubject();
//	    if(subject == null){
//	    	LoggerUtils.debug(UserSessionFilter.class, "sdsadafsd");
//	    }
//	    Session session = subject.getSession();
//	   String username = (String) session.getAttribute(GlobalConstant.SESSION_AUTH_LOGIN_USERNAME);
//	   if(username == null){
//		  String newusername =  (String) subject.getPrincipal();
//		  session.setAttribute(GlobalConstant.SESSION_AUTH_LOGIN_USERNAME, newusername);
//	   }
		return true;
	}

	@Override
	protected boolean onAccessDenied(ServletRequest request,
			ServletResponse response) throws Exception {
		LoggerUtils.debug(UserSessionFilter.class, "onAccessDenied");
		return true;
	}

}
